package com.huawei.rbac.web.controller;

import com.huawei.rbac.domain.Permission;
import com.huawei.rbac.query.QueryObject;
import com.huawei.rbac.result.PageResult;
import com.huawei.rbac.service.IPermissionService;
import com.huawei.rbac.util.RequiredRermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IPermissionService service;

    @RequestMapping("/list")
    @RequiredRermission({"权限列表","permission:list"})
    public String list(Model model, QueryObject qo){
        PageResult<Permission> result = service.query(qo);
        model.addAttribute("result",result);
        return "permission/list";
    }

    @RequestMapping("/delete")
    @RequiredRermission({"权限删除","permission:delete"})
    public String delete(Long id){
        if(id != null){
            service.delete(id);
        }
        return "redirect:/permission/list";
    }

    @RequestMapping("/reload")
    @RequiredRermission({"权限加载","permission:reload"})
    public String reload(){
        service.reload();
        return "redirect:/permission/list";
    }
}
